import urllib.request
import chardet


total = 1
user = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'
with open('urls.txt','r') as f1:
    for i in f1:
        name = 'url_'
        req = urllib.request.Request(i)
        req.add_header('User-Agent',user)

        
        response = urllib.request.urlopen(req)
        html=response.read()
        dict1=chardet.detect(html)
        code = dict1['encoding']
        response = urllib.request.urlopen(req)
        html=response.read().decode(code)
        name += str(total)+'.txt'
        with open(name,'w',encoding=code) as f2:
            f2.writelines(html)
        total+=1
